<?php

namespace Admin\Controller;
use User\Api\UserApi;
header('content-type:text/html;charset=utf8');
class SxzController extends AdminController {

    public function index(){
    	$nickname       =   I('nickname');
            $map['status']  =   array('egt',0);
            if(is_numeric($nickname)){
                $map['id|vname']=   array(intval($nickname),array('like','%'.$nickname.'%'),'_multi'=>true);
            }else{
                $map['vname']    =   array('like', '%'.(string)$nickname.'%');
            }
            
            $list   = $this->lists('values',$map,'id asc');
            // dump($res);die;
            int_to_string($list);
            $this->assign('_list', $list);
            
            $this->meta_title = '属性值';
            $this->display();
    }

	public function del($id=''){
		$res=M('values')->where(array('id'=>$id))->delete();
		if($res){
			$this->success('删除成功');
		}else{
			$this->error('删除失败');
		}
}

    public function addsxz($id='',$n='',$g=''){
    	if(IS_POST){
    			$qus=I("post.");
              	$qus['gid']=$g;
              	$qus['cid']=$id;
              	// dump($qus);die;
                $Link = D("values");
                $res = $Link->create(); // dump($qus);die;
                if($res){
                    if($Link->add($qus)){
                        $this->success('添加成功');
                    }else{
                        $this->error('添加失败');
                    }
                }else{
                    $this->error(D("values")->getError());
                }
            }else{
            	$this->assign('gid',$g);
            	$this->assign('id',$id);
                $this->assign('name',$n);
    			$this->display();
            }
    }
    public function CartesianProduct($sets){
            // 保存结果
            $result = array();
            // 循环遍历集合数据
            for($i=0,$count=count($sets); $i<$count-1; $i++){
            // 初始化
            if($i==0){
            $result = $sets[$i];
            }
            // 保存临时数据
            $tmp = array();
            // 结果与下一个集合计算笛卡尔积
            foreach($result as $res){
            foreach($sets[$i+1] as $set){
            $tmp[] = $res.$set;
            }
            }
            // 将笛卡尔积写入结果
            $result = $tmp;
            }
            return $result;
    }
    public function bianji($id='',$n=''){
    	if(IS_POST){
    		$Fri = D('sxz');
                //dump(I('post.'));
                $data = $Fri->create();
                $data['id']=$id;
                //dump($data);
                if($data){
                    if($Fri->save($data)){
                        $this->success('更新成功');
                    }else{
                        $this->error('更新失败');
                    }
                }else{
                    $this->error($Fri->getError());
                }
    	}else{
    		$this->assign('name',$n);
    		$this->assign('id',$id);
    		$this->display();
    	}
    	
    }
}